﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Jemgine.Hex
{
    public enum SubdivisionTechniques
    {
        /// <summary>
        /// Each subdivision switches orientation and creates smaller hexes on hex verticies.
        /// </summary>
        AlternateOrientation,

        /// <summary>
        /// Radius of hex is divided by three. Seven hexes fit inside original hex.
        /// </summary>
        DivideByThree,
    }

    public enum Orientation
    {
        /// <summary>
        /// Hexes have a flat edge facing north
        /// </summary>
        Horizontal,

        /// <summary>
        /// Hexes have a point facing north
        /// </summary>
        Vertical
    }

    public interface CoordinateSystem
    {
        /// <summary>
        /// Create a new Coordinate Space that subdivides this coordinate space
        /// </summary>
        /// <param name="Technique">The Technique to use for subdivision.</param>
        /// <returns></returns>        
        CoordinateSystem CreateSubSpace(SubdivisionTechniques Technique);
        
        /// <summary>
        /// Find the origin of a hex
        /// </summary>
        /// <param name="Coordinate">Hex coordinate</param>
        /// <returns>Lower-left corner of rectangular bounds of hex</returns>
        Vector2 Origin(Coordinate Coordinate);

        /// <summary>
        /// Find the center of a hex
        /// </summary>
        /// <param name="Coordinate">Hex coordinate</param>
        /// <returns>Center point of hex</returns>
        Vector2 Center(Coordinate Coordinate);

        /// <summary>
        /// Find the coordinate of a hex's neighbor
        /// </summary>
        /// <param name="tile">Hex coordinate</param>
        /// <param name="direction">Direction of neighbor. 
        /// If Vertical hexes, only results from Vertical* directions are valid. 
        /// If Horizontal hexes, only results from Horizontal* directions are valid.</param>
        /// <returns>Coordinate of neighbor</returns>
        Coordinate Neighbor(Coordinate tile, Direction direction);

        /// <summary>
        /// Find the hex at a point. 
        /// Remember to apply SuperOffsets to world coordinates when tile picking in subdivided spaces.
        /// </summary>
        /// <param name="worldCoordinate">Vector2 in World Space, where World Space is defined from the origin of hex[0,0]</param>
        /// <returns>Hex coordinate</returns>
        Coordinate TileAt(Vector2 worldCoordinate);

        /// <summary>
        /// Get the offset of this space from it's parent space.
        /// Spaces are positioned such that the center of hex[0,0] is equal in all spaces.
        /// </summary>
        /// <returns></returns>
        Vector2 GetSuperOffset();

        /// <summary>
        /// Get the orientation of this space.
        /// </summary>
        /// <returns>Orientation.Horizontal or Orientation.Vertical</returns>
        Orientation GetOrientation();

        /// <summary>
        /// Get the radius of hexes in this space
        /// </summary>
        /// <returns>The distance from hex center to a hex vertex</returns>
        double GetRadius();

        /// <summary>
        /// Find the hex coordinate of the center hex in the subspace.
        /// </summary>
        /// <param name="SubSpace"></param>
        /// <param name="Coord"></param>
        /// <returns></returns>
        Coordinate GetSubCenter(CoordinateSystem SubSpace, Coordinate Coord);

        SubdivisionTechniques CreationTechnique { get; }
    }
}

   